//
//  CameraManCell.m
//  XDBaseFrameWork
//
//  Created by xindao on 14-9-22.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "CameraManCell.h"
#import "XDTools.h"
#import "UIImageView+WebCache.h"
@implementation CameraManCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)createViews{
    _headIV = [[UIImageView alloc] initWithFrame:CGRectMake(8, 7.5, 65, 65)];
    _headIV.backgroundColor = UIColorFromRGB(0xeaeaea);
    _headIV.layer.masksToBounds = YES;
    _headIV.layer.cornerRadius = 32.5f;
    _headIV.image = LOADIMAGE(@"placeholderHeader@2x");
    [self.contentView addSubview:_headIV];

    _nameLB = [UILabel initLabelText:@"" andRect:CGRectMake(VIEW_POINT_MAX_X(_headIV)+10, 13, 110, 19) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
    _nameLB.numberOfLines = 0;
    [self.contentView addSubview:_nameLB];
    
    _renzhengIV = [[UIImageView alloc] initWithFrame:CGRectMake(VIEW_POINT_MAX_X(_headIV)+10, 9.5f, 14, 14)];
    _renzhengIV.image = [UIImage imageNamed:@"renzheng"];
    _renzhengIV.hidden = YES;
    [self.contentView addSubview:_renzhengIV];
    
    _jibieLB = [UILabel initLabelText:@"" andRect:CGRectMake(_nameLB.frame.origin.x, height_y(_nameLB), 70, 14) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:UIColorFromRGB(0x9d9d9d) andTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_jibieLB];
    
//    _numIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"orderNum"]];
//    _numIV.frame = CGRectMake(_jibieLB.frame.origin.x, 55, 8, 10);
//    [self.contentView addSubview:_numIV];
    
    _favNumIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"favNum"]];
    _favNumIV.frame = CGRectMake(_jibieLB.frame.origin.x, 54, 11, 10);
    [self.contentView addSubview:_favNumIV];

    _numberLB = [UILabel initLabelText:@"" andRect:CGRectMake(VIEW_POINT_MAX_X(_numIV), height_y(_jibieLB)+7, 70, 15) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:UIColorFromRGB(0x9d9d9d) andTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_numberLB];
    
    _favNumLB = [UILabel initLabelText:@"" andRect:CGRectMake(_jibieLB.frame.origin.x, height_y(_jibieLB)+7, 70, 15) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:UIColorFromRGB(0x9d9d9d) andTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_favNumLB];

    _distanceLB = [UILabel initLabelText:@"" andRect:CGRectMake(UI_SCREEN_WIDTH-10-100, 33, 100, 12) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:UIColorFromRGB(0x9d9d9d) andTextAlignment:NSTextAlignmentRight];
    _distanceLB.hidden = YES;
    [self.contentView addSubview:_distanceLB];

//    _junjiaLB = [UILabel initLabelText:@"均价" andRect:CGRectMake(193, 33, 25, 13) andBackGroudColor:UIColorFromRGB(0x919191) andTextFont:[UIFont boldSystemFontOfSize:11] andTextColor:[UIColor whiteColor] andTextAlignment:NSTextAlignmentCenter];
//    _junjiaLB.layer.masksToBounds = YES;
//    _junjiaLB.layer.cornerRadius = 6;
//    [self.contentView addSubview:_junjiaLB];

    _priceLB = [UILabel initLabelText:@"" andRect:CGRectMake(VIEW_POINT_MAX_X(_junjiaLB), 12, 130, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:18] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_priceLB];
    
    _normalPriceLB = [UILabel initLabelText:@"" andRect:CGRectMake(UI_SCREEN_WIDTH-100, height_y(_jibieLB)+7, 110, 15) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:11] andTextColor:UIColorFromRGB(0x9d9d9d) andTextAlignment:NSTextAlignmentRight];
    [self.contentView addSubview:_normalPriceLB];
    
    _huiLB = [UILabel initLabelText:@"起" andRect:CGRectMake(VIEW_POINT_MAX_X(_priceLB), 33, 12, 12) andBackGroudColor:mClearColor andTextFont:[UIFont boldSystemFontOfSize:11] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_huiLB];

//    for (int i = 0; i < 2; i++) {
//        UIView * lineView = [UIView initViewRect:CGRectMake(0, 79.5f*i, UI_SCREEN_WIDTH, .5f) andBackGroudColor:RGBA(236, 232, 229, 1)];
//        [self.contentView addSubview:lineView];
//    }
    
    _jibieIV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 12)];
    [self.contentView addSubview:_jibieIV];
    
    
    UIImageView * longXuXian = [[UIImageView alloc] initWithFrame:CGRectMake(0, 79.5f, UI_SCREEN_WIDTH, .5f)];
    longXuXian.image = [UIImage imageNamed:@"xuxian_long"];
    [self.contentView addSubview:longXuXian];
    
    UIImageView * shortXuXian = [[UIImageView alloc] initWithFrame:CGRectMake(85, height_y(_jibieLB)+3, 226, .5f)];
    shortXuXian.image = [UIImage imageNamed:@"xuxian_short"];
    [self.contentView addSubview:shortXuXian];
}

- (void)initViewsWithDict:(NSDictionary *)dict{
    
    [_headIV sd_setImageWithURL:[NSURL URLWithString:dict[@"EmplAvator"]] placeholderImage:LOADIMAGE(@"placeholderHeader@2x")];

    _nameLB.frame = CGRectMake(VIEW_POINT_MAX_X(_headIV)+10, 10, 70, 25);
    _nameLB.text = dict[@"EmplName"];
    [_nameLB sizeToFit];
    if (_nameLB.bounds.size.width > 70) {
        _nameLB.frame = CGRectMake(VIEW_POINT_MAX_X(_headIV)+10, 10, 70, 25);
    }
    
    if ([dict[@"IsAuthen"] intValue]) {
        _renzhengIV.hidden = NO;
        _renzhengIV.frame = CGRectMake(VIEW_POINT_MAX_X(_nameLB), 12.5f, 14, 14);
    }else{
        _renzhengIV.hidden = YES;
    }
    
    _jibieLB.text = dict[@"LevelName"];
    
    _favNumLB.frame = CGRectMake(VIEW_POINT_MAX_X(_favNumIV), _favNumIV.frame.origin.y-2, 20, 15);
    _favNumLB.text = dict[@"CollectionCount"];
    [_favNumLB sizeToFit];
    
    _numberLB.text = [NSString stringWithFormat:@"共接单%@次",dict[@"OrderCount"]];
    [_numberLB sizeToFit];
    _numberLB.frame = CGRectMake(UI_SCREEN_WIDTH-10-_numberLB.bounds.size.width, _favNumLB.frame.origin.y, _numberLB.bounds.size.width, _numberLB.bounds.size.height);
    
    _distanceLB.text = [NSString stringWithFormat:@"服务范围 %@",dict[@"FWCity"]];
    _priceLB.text = [NSString stringWithFormat:@"￥%@",dict[@"Price"]];
    [_priceLB sizeToFit];
    _priceLB.frame = CGRectMake(UI_SCREEN_WIDTH-24-_priceLB.bounds.size.width, 12, 130, 20);
//    _junjiaLB.frame = CGRectMake(_priceLB.frame.origin.x-25, 33, 25, 13);
    _huiLB.frame = CGRectMake(UI_SCREEN_WIDTH-24, 18, 12, 12);
    
//    _normalPriceLB.text = [NSString stringWithFormat:@"市场参考价 %@",dict[@"MarketPrice"]];
//    [_normalPriceLB sizeToFit];
//    _normalPriceLB.frame = CGRectMake(UI_SCREEN_WIDTH-_normalPriceLB.bounds.size.width-15, height_y(_priceLB), _normalPriceLB.bounds.size.width, 15);
    
    
    _jibieIV.image = nil;
    
//    int num = [dict[@"OrderCount"] intValue];
//    if (num >= 250) {
//        num = 249;
//    }else if (!num) {
//        num = 1;
//    }
    
    NSInteger num = [XDTools changeOrderCountToLevel:[dict[@"Score"]integerValue]];
    _jibieIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"seller-%d-%d@2x",num/5+1,num%5+1]];
    _jibieIV.frame = CGRectMake(UI_SCREEN_WIDTH-10-(num%5+1)*12, 33, (num%5+1)*12, 12);
    
//    _jibieIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"seller-%d-%d@2x",num/50+1,num%50/10+1]];
//    _jibieIV.frame = CGRectMake(UI_SCREEN_WIDTH-10-(num%50/10+1)*12, 33, (num%50/10+1)*12, 12);
}

- (void)initFreePaiViewsWithDict:(NSDictionary *)dict{
    
    [self initViewsWithDict:dict];
    
    _jibieIV.hidden = YES;
    
    _distanceLB.hidden = NO;
    _distanceLB.text = [NSString stringWithFormat:@"距您%@公里",dict[@"Range"]];
    
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
